package com.asiainfo.controller;



import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;

import com.asiainfo.bean.RechargeBean;
import com.asiainfo.bean.UserSessionBean;
import com.asiainfo.dao.BaseDao;
import com.asiainfo.util.SessionInfoUtil;

@Controller
@RequestMapping("/rechargeController")
public class RechargeController extends ModelAndView{
	
	private Logger logger = LogManager.getLogger(this.getClass());
	
	
	/**
	 * 数据操作封装DAO
	 */
	@Autowired
	private BaseDao dao;

	/**
	 * 方法描述：跳转到充值记录页面
	 * 
	 * return 充值记录页面Model
	 */
	@RequestMapping("/recordView.do")
	public ModelAndView index() {
		this.setViewName("helper/rechargeRecord");
		
		return this;	
		}

	
	/**
	 * 方法描述：查看充值记录操作
	 * 
	 */
	@RequestMapping(value = "/record.do")
	 
	public @ResponseBody
	JSONObject record(@RequestBody RechargeBean rechargeBean, 
			HttpServletRequest request) throws Exception {
		JSONObject retMsg = new JSONObject();
		
        UserSessionBean userSessionBean = SessionInfoUtil.getUserSessBean(request.getSession());
		String userPhone = userSessionBean.getPhone();
		
		
		if(userPhone !=null){
			
			
			//判断该充值记录表是否有该号码
			int isRecord = (Integer)this.dao.getDAO().selectOne(
					"RechargeMapper.isRecord", rechargeBean);
			
			this.addObject("isRecord", isRecord);
			
			if (isRecord!=0) {
				
				List<RechargeBean> list = this.dao.getDAO().selectList(
						"RechargeMapper.queryRecord", rechargeBean);
				
				this.addObject("resList", list);
				
		
 			
 			retMsg.put("flag", true);
			}else{
				retMsg.put("nodata", true);
			}
			
		}else{
			retMsg.put("flag", false);
		}
		return retMsg;
	}
}
